package com.superpai.activity;

import android.os.Bundle;
import android.view.View;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemSelectedListener;
import android.widget.ArrayAdapter;
import android.widget.EditText;
import android.widget.Spinner;
import android.widget.TextView;

import com.superpai.R;
import com.superpai.common.Constants;
import com.superpai.utils.AndroidUtils;
import com.superpai.utils.StringUtils;

/**
 * @author Devin.Hu
 * @date 2011-8-29
 * @version V1.0
 * @description 用户反馈页面
 */
public class FeedbackActivity extends BaseActivity implements OnItemSelectedListener {

	private EditText feedback_editContent;
	private TextView feedback_submit;
	private Spinner feedbcktype;
	private String[] typeArray = { "拍拍店铺", "应用开发者"};
	private String[] emailArray = new String[]{Constants.sellEmail,Constants.EMAIL};
	private String feedEmail;
	
	@Override
	public void onCreate(Bundle paramBundle) {
		super.onCreate(paramBundle);
		this.setContentView(R.layout.feedback);
		initMenuView(this, mIndexMore);
		initViews();
	}

	private void initViews(){
		title = (TextView)this.findViewById(R.id.title);
		title.setText(R.string.more_feedback_title);
		
		ArrayAdapter<String> typeAdapter = new ArrayAdapter<String>(mContext, android.R.layout.simple_spinner_item,typeArray);
		typeAdapter.setDropDownViewResource(android.R.layout.select_dialog_singlechoice);
		feedbcktype = (Spinner)this.findViewById(R.id.feedbcktype);
		feedbcktype.setAdapter(typeAdapter);
		feedbcktype.setOnItemSelectedListener(this);
		
		feedback_editContent = (EditText)this.findViewById(R.id.feedback_editContent);
		feedback_submit = (TextView)this.findViewById(R.id.feedback_submit);
		feedback_submit.setOnClickListener(this);
	}
	
	@Override
	public void onClick(View v) {
		checkMenu(v);
		if(v == feedback_submit){
			String message = feedback_editContent.getText().toString();
			if(StringUtils.isEmpty(message)){
				AndroidUtils.Toast(mContext,mContext.getString(R.string.feedback_message_notnull));
			}else{
				AndroidUtils.sendEmail(mContext , feedEmail, message);
			}
		}
	}

	@Override
	public Object doDataConnection(int type) {
		return null;
	}

	@Override
	public void doProcessData(int type, Object... values) {
		
	}

	@Override
	public void onItemSelected(AdapterView<?> arg0, View arg1, int position, long arg3) {
		feedEmail = emailArray[position]; 
	}

	@Override
	public void onNothingSelected(AdapterView<?> arg0) {
		feedEmail = emailArray[0]; 
	}

	@Override
	protected void onDestroy() {
		super.onDestroy();
		disConnection();
	}
}
